﻿// =================================================================== 
// Module说明
//====================================================================
// 创建时间：2018-12-04 10:19:31
// 负责人：Sushee
// ===================================================================
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq.Expressions;
using OF.Utility;
using OF.Component.Model;
using OF.Component.IDAL;
using OF.Component.Factory;
namespace OF.Component.BLL
{
	
	/// <summary>
	///菜单角色关联表 扩展
	/// </summary>
	public partial class AuthorityRoleMenuRelaOperate
	{
        /// <summary>
    	/// 根据断言条件获取单个菜单角色关联表
    	/// </summary>
        public static AuthorityRoleMenuRelaInfo QuerySingle(Expression<Func<AuthorityRoleMenuRelaInfo, bool>> predicate)
        {
            return dal.QuerySingle(predicate);
        }
        /// <summary>
    	/// 根据断言条件获获取菜单角色关联表列表
    	/// </summary>
        public static IList<AuthorityRoleMenuRelaInfo> QueryList(Expression<Func<AuthorityRoleMenuRelaInfo, bool>> predicate)
        {
            return dal.QueryList(predicate);
        }

        /// <summary>
        /// 根据角色获取菜单 
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="SystemID"></param>
        public static IList<AuthorityMenuInfo> GetRoleMenuList(int userId, string SystemCode)
        {
            //if (SystemCode== "111111")
            //{
            //    return AuthorityMenuOperate.QueryList(a => a.IsActive == 1);
            //}
            List<int> roleList = new List<int>();
            IList<AuthorityUserRoleRelaInfo> list = AuthorityUserRoleRelaOperate.QueryList(a => a.IsActive == 1 && a.UserID == userId);
            foreach (var item in list)
            {
                roleList.Add(item.RoleID);
            }
            return dal.GetRoleMenuList(roleList, SystemCode);
        }

        /// <summary>
        /// 根据角色ID获取操作权限字符串
        /// </summary>
        /// <param name="RoleID">角色ID</param>
        /// <returns>菜单ID串</returns>
        public static void GetAuthorityToString(int RoleID,out string MenuString,out string SystemString)
        {
            MenuString = ",";
            List<int> sysList = new List<int>();
            IList<AuthorityRoleMenuRelaInfo> list = null;
            list = GetRoleMenuBySystemIDandRoleID(RoleID);
            foreach (AuthorityRoleMenuRelaInfo info in list)
            {
                MenuString += info.MenuID.ToString() + ",";
                if (!sysList.Contains(info.SystemID))
                {
                    sysList.Add(info.SystemID);
                }
            }
            SystemString = "," + string.Join(",", sysList.ToArray()) + ",";
        }

        ///<summary>
        ///根据ID取出信息
        ///</summary>
        public static IList<AuthorityRoleMenuRelaInfo> GetRoleMenuBySystemIDandRoleID(int RoleID)
        {
            IList<AuthorityRoleMenuRelaInfo> list = null;
            list = dal.GetRoleMenuBySystemIDandRoleID(RoleID);
            return list;
        }

        /// <summary>
        /// 删除权限        
        /// </summary>
        /// <param name="RoleID"></param>
        public static void DeleteRoleMenu(int RoleID)
        {
            dal.DeleteRoleMenu(RoleID);
        }

        /// <summary>
        /// 删除父级角色以下所有权限配置
        /// </summary>
        /// <param name="pRoleId"></param>
        public static void DeleteRoleMenuByParentRoleId(int pRoleId)
        {
            dal.DeleteRoleMenuByParentRoleId(pRoleId);
        }
    }
}